#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    int n;
    cin>>n;
    vector<ll> a(n);
    ll res=0,f=0;
    unordered_map<ll,ll> mp;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	mp[a[i]]++;
    	if(mp[a[i]]==2){
    		f++;
    		res+=2*a[i];
    		mp[a[i]]-=2;
    	}
	}

	if(res==0){
		cout<<0<<'\n';
		return;
	}

	vector<ll> e;
	for(auto [x,y]:mp){
		if(y){
			e.push_back(x);
		}
	}
	sort(e.begin(),e.end());

	if(f==1){
		ll temp=0;
		for(ll x:e){
			if(x<res)temp=x;
			else break;
		}
		if(temp){
			cout<<res+temp<<'\n';
			return;
		}
		cout<<0<<'\n';
		return;
	}

	ll r1=0,r2=0;
	if(e.size()==1){
		if(e[0]<res){
			cout<<res+e[0]<<'\n';
			return;
		}else{
			cout<<res<<'\n';
			return;
		}
	}

	for(int i=e.size()-1;i>=1;i--){
		if(e[i]-e[i-1]<res){
			cout<<res+e[i]+e[i-1]<<'\n';
			return;
		}
	}
	cout<<res<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}